package com.zb.network.controller;

import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjNetworkStrategyService;
import com.zb.utils.TokenUtil;
import com.zb.vo.NetworkWithdrawWithFeeEmpRootUpdateVo;
import com.zb.vo.OrderWithdrawHandlingFeeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * @Author WEN
 * @Date 2024/4/11 0011
 **/
@Api(tags = "服务商策略类接口")
@RestController
@RequestMapping("/network/strategy")
public class ZjNetworkStrategyController {
    @Resource
    private ZjNetworkStrategyService networkStrategyService;

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商列表 - 批量更新服务商接单策略")
    @ApiOperation("批量更新服务商接单策略")
    @PostMapping("/updateAutoSureReceiveOrder")
    public Result updateAutoSureReceiveOrder(@RequestParam @ApiParam(value = "是否自动接单：false-手动确认，true-自动接单", required = true, example = "true") boolean autoSureReceiveOrder,
                                     @RequestBody @ApiParam(value = "服务商ID", required = true) List<Long> networkIds) {
        networkStrategyService.updateAutoSureReceiveOrderBatchById(networkIds, autoSureReceiveOrder);
        return Result.success("更新服务商接单策略成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商列表 - 批量更新服务商审核取消工单策略")
    @ApiOperation("批量更新服务商审核取消工单策略")
    @PostMapping("/updateAutoCheckCancelOrder")
    public Result updateAutoCheckCancelOrder(@RequestParam @ApiParam(value = "是否自动审核取消工单：false-手动审核，true-自动审核", required = true, example = "false") boolean autoCheckCancelOrder,
                                             @RequestBody @ApiParam(value = "服务商ID", required = true) List<Long> networkIds) {
        networkStrategyService.updateAutoCheckCancelOrderBatchById(networkIds, autoCheckCancelOrder);
        return Result.success("更新服务商审核取消工单策略成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商列表 - 批量更新服务商审核结单策略")
    @ApiOperation("批量更新服务商审核结单策略")
    @PostMapping("/updateAutoCheckEndOrder")
    public Result updateAutoCheckEndOrder(@RequestParam @ApiParam(value = "是否自动审核结单：false-手动审核，true-自动审核", required = true, example = "false") boolean autoCheckEndOrder,
                                             @RequestBody @ApiParam(value = "服务商ID", required = true) List<Long> networkIds) {
        networkStrategyService.updateAutoCheckEndOrderBatchById(networkIds, autoCheckEndOrder);
        return Result.success("更新服务商审核结单策略成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商列表 - 批量更新允许更改备件价格")
    @ApiOperation("批量更新允许更改备件价格")
    @PostMapping("/enableUpdateSparePrice")
    public Result enableUpdateSparePrice(@RequestParam @ApiParam(value = "是否允许更改备件价格：false-关闭，true-允许修改", required = true, example = "false") boolean enableUpdateSparePrice,
                                             @RequestBody @ApiParam(value = "服务商ID", required = true) List<Long> networkIds) {
        networkStrategyService.updateEnableUpdateSparePriceBatchById(networkIds, enableUpdateSparePrice);
        return Result.success("更改备件价格策略成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.NETWORK_TYPE, type = OperationLogType.UPDATE, remark = "服务区域-服务商列表 - 批量更改提现手续费")
    @ApiOperation("批量更改提现手续费")
    @PostMapping("/updateOrderWithdrawHandlingFee")
    public Result updateOrderWithdrawHandlingFee(@RequestBody @Valid OrderWithdrawHandlingFeeVo handlingFeeVo) {
        networkStrategyService.updateOrderWithdrawHandlingFee(handlingFeeVo);
        return Result.success("提现手续费更改成功");
    }

    @ApiOperation("根据服务商ID获取提现手续费策略")
    @GetMapping("/getWithdrawHandlingFeeStrategy/{networkId}")
    public Result getWithdrawHandlingFeeStrategy(@PathVariable @ApiParam(value = "服务商ID", required = true) Long networkId) {
        return Result.success("获取提现手续费策略成功").data(PageUtil.row(networkStrategyService.getNetworkWithdrawHandlingFeeStrategy(networkId)));
    }

    @ApiOperation("批量更改提现策略")
    @PostMapping("/updateWithdrawEmpRoot")
    public Result updateWithdrawEmpRoot(HttpServletRequest request, @RequestBody @Valid NetworkWithdrawWithFeeEmpRootUpdateVo withdrawEmpRootVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkStrategyService.updateWithdrawEmpRoot(custAccId, withdrawEmpRootVo);
        return Result.success("更改提现策略成功");
    }

    @ApiOperation("批量更改查询费用策略")
    @PostMapping("/updateSelectFeeEmpRoot")
    public Result updateSelectFeeEmpRoot(HttpServletRequest request, @RequestBody @Valid NetworkWithdrawWithFeeEmpRootUpdateVo withdrawEmpRootVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        networkStrategyService.updateSelectFeeEmpRoot(custAccId, withdrawEmpRootVo);
        return Result.success("更改查询费用策略");
    }



}
